import 'package:flutter/material.dart';

import 'home.dart';

class LaunchPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() => _LaunchPageState();
}

class _LaunchPageState extends State<LaunchPage> {

  @override
  void initState() {     
    super.initState();
    startHome();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // body: Container(
      //   color: Colors.red,
      //   child: Text('flutter') 
      // )
      body: Image.asset("assets/images/launch_image.jpg", 
        width: double.infinity, height: double.infinity, fit: BoxFit.fill),
    );
  }

  void startHome() async {

    var now7 = DateTime.now();
    print('-->> launch start: $now7');

    //延迟 3秒跳转到主界面(这里的单位是微秒)
    await Future.delayed(const Duration(microseconds: 3000000), (){

      //根据 App 启动的效果得知，先显示原生的启动图，然后显示 flutter 的启动页
      var now8 = DateTime.now();
      print('-->> launch delayed: $now8');

      Navigator.pushReplacement(
        context, 
        MaterialPageRoute(builder: (context) => HomePage()),
      );
    });
  }
}